package com.lmt.controller;

import com.lmt.common.entity.Result;
import com.lmt.common.util.PasswordUtil;
import com.lmt.common.util.ResultUtil;
import com.lmt.entity.UserInfo;
import com.lmt.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/userInfo")
public class UserInfoController {

    private final UserInfoService userInfoService;

    @Autowired
    public UserInfoController(UserInfoService userInfoService) {
        this.userInfoService = userInfoService;
    }

    @RequestMapping("/registered")
    public Result registered(@RequestBody UserInfo userInfo){
        PasswordUtil.setSaltAndEncodedPassword(userInfo);
        userInfoService.save(userInfo);
        return ResultUtil.success(userInfo);
    }

}
